$(function(){
	//loadTipMsg();
	$.permission.showWelcomeTools("20170714211441802549642","welcomeTools");
	loadArticleLimitData("",7,"newest","neweasstArea");
	loadNoticeLimitData("",7,"newest","neweasstNoticeArea");
	//加载待办事项
	loadTodoList();
	loadMsgList();
	checkDefaultPassword();
});

/**
 * 检测用户密码是否是默认密码，如果是提示用户进行修改密码
 * @returns
 */
function checkDefaultPassword(){
	$.ajax({
	    type : "post",
	    url : getBasePath()+"adminUser/checkDefaultPassword.do",
	    data : {},
		cache : true,
		async : true,
		dataType : "json",
		success : function(response){
			if(response.code=="00"){
				$.messager.confirm('确认对话框', '检测到你的密码为8个8的默认密码,是否现在修改密码？', function(flag){
				     if (flag){
				    	 editPassword();
				     }
				});
			}
		}
	});
}

/**
 * 加载数据列表
 */
function loadMsgList(){
	console.log("coming....");
	$('#msgArea').datalist({
	    url:getBasePath()+'siteMsg/getSiteMsgListLimit15.do',
	    striped:true,
	    nowrap:false,
	    width:'100%',
	    onClickRow:function(index, row){
	    	showDetail(row.id);
	    },
	    queryParams:{
	    },
	    lines: true
	});
}

//展示详情页
  function showDetail(id){
	//验证是否登录--开始
  	if(!checkLoginStatus()){return;}
      //验证是否登录--结束
  	var editDataFormArea = $("#editDataFormArea");
	if(editDataFormArea.length==0){
		$("<div id='editDataFormArea'></div>").prependTo("body");
	}
	var _width = 650;
	var _height = 480;
		
  	$("#editDataFormArea").window({
  	    title: '查看消息明细',
  	    width: _width,
  	    height: _height,
  	    iconCls:'icon-user',
  	    closed: false,
  	    cache: false,
  	    modal: true,
  	    onClose:function(){
		    $("#editDataFormArea").html("");
		    $("#editDataFormArea").remove();
		},
		href:getBasePath()+"siteMsg/getSiteMsgDetail.do?id="+id
  	});
  }

/**
 * 获取通知列表
 * @param articleTypeId
 * @param limitSize
 * @returns
 */
function loadNoticeLimitData(noticeTypeId,limitSize,selectType,renderId){
	$.ajax({
	    type : "post",
	    url : getBasePath()+"noticeInfo/getNoticeListForLimit.do",
	    data : {noticeTypeId:noticeTypeId,limitSize:limitSize,selectType:selectType},
		cache : true,
		async : true,
		dataType : "json",
		success : function(response){
			console.log(response);
			if(response.code=="00"){
				if(response.data.length>0){
					var listHtml = "";
					$.each(response.data,function(i,bean){
						var title = bean.title;
						if(bean.title.length>38){
							title = bean.title.substring(0,38)+"...";
						}
						listHtml+='<li><a href="javascript:loadNoticeDetail('+bean.id+')" target="_blank">'+title+'<b>'+bean.editTime+'</b></li>';
					});
					console.log(renderId);
					$("#"+renderId).html(listHtml);
				}
			}else{
				console.log(response.msg);
			}
		}
	});
}

/**
 * 查看通知详情
 * @param id
 * @returns
 */
function loadNoticeDetail(id){
	var editDataFormArea = $("#editDataFormArea");
		if(editDataFormArea.length==0){
			$("<div id='editDataFormArea'></div>").prependTo("body");
		}
		
 	$("#editDataFormArea").window({
 	    title: '查看公告明细',
 	    width: '95%',
 	    height: '95%',
 	    iconCls:'icon-window',
 	    closed:false,
 	    cache: false,
 	    modal: true,
 	    onClose:function(){
		    $("#editDataFormArea").html("");
		    $("#editDataFormArea").remove();
		},
		href:getBasePath()+"noticeInfo/getNoticeInfoDetail.do?id="+id
 	});
}

/**
 * 获取资讯列表
 * @param articleTypeId
 * @param limitSize
 * @returns
 */
function loadArticleLimitData(articleTypeId,limitSize,selectType,renderId){
	$.ajax({
	    type : "post",
	    url : getBasePath()+"article/getArticleListForLimit.do",
	    data : {articleTypeId:articleTypeId,limitSize:limitSize,selectType:selectType},
		cache : true,
		async : true,
		dataType : "json",
		success : function(response){
			console.log(response);
			if(response.code=="00"){
				if(response.data.length>0){
					var listHtml = "";
					$.each(response.data,function(i,bean){
						var articleTitle = bean.articleTitile;
						var editTime = bean.editTime;
						if(bean.articleTitile.length>25){
							articleTitle = bean.articleTitile.substring(0,25)+"...";
						}
						listHtml+='<li><a href="javascript:loadArticleDetail('+bean.id+')" target="_blank">'+articleTitle+'  ['+editTime+']</li>';
					});
					console.log(renderId);
					$("#"+renderId).html(listHtml);
				}
			}else{
				console.log(response.msg);
			}
		}
	});
}

//显示资讯详情
function loadArticleDetail(id){
	var editDataFormArea = $("#editDataFormArea");
	if(editDataFormArea.length==0){
		$("<div id='editDataFormArea'></div>").prependTo("body");
	}
  	$("#editDataFormArea").window({
  	    title: '查看资讯明细',
  	    width: '95%',
	    height: '95%',
  	    iconCls:'icon-window',
  	    closed: false,
  	    cache: false,
  	    modal: true,
  	    onClose:function(){
		    $("#editDataFormArea").html("");
		    $("#editDataFormArea").remove();
		},
		href:getBasePath()+"article/getArticleDetail.do?id="+id
  	});
}


//加载提示信息
function loadTipMsg() {
	$.ajax({
	    type : "post",
	    url : getBasePath()+"adminUser/queryTodoListCount.do",
	    data : {},
		cache : true,
		async : true,
		dataType : "json",
		success : function(response){
			console.log(response);
			if(response.code=="00"){
				var msgHtml = "";
				var rightUrl = "";
				var leftUrl = "";
				var urlString = "";
				if(response.data.checkDocCount>0){
					rightUrl = getBasePath()+"manage/office/checkDocList.jsp?selectType=myRecive";
					leftUrl = getBasePath()+"manage/menuLeft.jsp?parentUUID=2015072023430136891068&&parentTitleName=公文管理";
					urlString = "javascript:redirectLeft('"+leftUrl+"','"+rightUrl+"')";
					msgHtml += "<span class='msgli'><a href=\""
						+ urlString
						+ "\">你有(<b>"
						+ response.data.checkDocCount
						+ "</b>)条公文待处理</a></span><br/>";
				}
				
				if(response.data.checkNoticeCount>0){
					rightUrl = getBasePath()+"manage/notice/noticeInfoList.jsp?checkStatus=0";
					leftUrl = getBasePath()+"manage/menuLeft.jsp?parentUUID=2015072023430224261625&&parentTitleName=公告管理";
					urlString = "javascript:redirectLeft('"+leftUrl+"','"+rightUrl+"')";
				    msgHtml += "<span class='msgli'><a href=\""
							+urlString+ "\">你有(<b>"
							+ response.data.checkNoticeCount
							+ "</b>)条公告待审批</a></span><br/>";
				}
				
				if(response.data.checkArticleCount>0){
					rightUrl = getBasePath()+"manage/article/articleList.jsp?checkStatus=0&saveType=0";
					leftUrl = getBasePath()+"manage/menuLeft.jsp?parentUUID=2015072023422339328564&&parentTitleName=%E8%B5%84%E8%AE%AF%E7%AE%A1%E7%90%86";
					urlString = "javascript:redirectLeft('"+leftUrl+"','"+rightUrl+"')";
					msgHtml += "<span class='msgli'><a href=\""
							+ urlString
							+ "\">你有(<b>"
							+ response.data.checkArticleCount
							+ "</b>)条资讯待审批</a></span><br/>";
				}
				
				$.messager.show({
					title : '我的消息',
					width : 300,
					height : 170,
					msg : msgHtml,
					timeout : 10000,
					showType : 'slide'
				});
			}else{
				console.log(response.msg);
			}
		}
	});
}

/**
 * 待办事项
 * @returns
 */
function loadTodoList(){
	$.ajax({
	    type : "post",
	    url : getBasePath()+"adminUser/queryTodoListCount.do",
	    data : {},
		cache : true,
		async : true,
		dataType : "json",
		success : function(response){
			console.log(response);
			if(response.code=="00"){
				var msgHtml = "";
				var rightUrl = "";
				var leftUrl = "";
				var urlString = "";
				if(response.data.checkDocCount>0){
					rightUrl = getBasePath()+"manage/office/checkDocList.jsp?selectType=myRecive";
					leftUrl = getBasePath()+"manage/menuLeft.jsp?parentUUID=2015072023430136891068&&parentTitleName=公文管理";
					urlString = "javascript:redirectLeft('"+leftUrl+"','"+rightUrl+"')";
					msgHtml += "<span class='todoList'><a href=\""
						+ urlString
						+ "\">你有(<b>"
						+ response.data.checkDocCount
						+ "</b>)条公文待处理</a></span><br/>";
				}
				
				if(response.data.checkNoticeCount>0){
					rightUrl = getBasePath()+"manage/notice/noticeInfoList.jsp?checkStatus=0";
					leftUrl = getBasePath()+"manage/menuLeft.jsp?parentUUID=2015072023430224261625&&parentTitleName=公告管理";
					urlString = "javascript:redirectLeft('"+leftUrl+"','"+rightUrl+"')";
				    msgHtml += "<span class='todoList'><a href=\""
							+urlString+ "\">你有(<b>"
							+ response.data.checkNoticeCount
							+ "</b>)条公告待审批</a></span><br/>";
				}
				
				if(response.data.checkArticleCount>0){
					rightUrl = getBasePath()+"manage/article/articleList.jsp?deleteFlag=0&saveType=0&checkStatus=0&parentUUID=20171012221036881568588";
					leftUrl = getBasePath()+"manage/menuLeft.jsp?parentUUID=2015072023422339328564&&parentTitleName=%E8%B5%84%E8%AE%AF%E7%AE%A1%E7%90%86";
					urlString = "javascript:redirectLeft('"+leftUrl+"','"+rightUrl+"')";
					msgHtml += "<span class='todoList'><a href=\""
							+ urlString
							+ "\">你有(<b>"
							+ response.data.checkArticleCount
							+ "</b>)条资讯待审批</a></span><br/>";
				}
				$("#toDoListArea").html(msgHtml);
			}else{
				console.log(response.msg);
			}
		 }
	});
}

/**
 * 改变左边框
 * @returns
 */
function redirectLeft(leftUrl,rightUrl){
	 parent.document.getElementById('rightFrame').src=rightUrl;
	 parent.document.getElementById('leftFrame').src=leftUrl;
}

function loadChart(){
	$('#containerForTongji').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: '系统信息发布统计'
        },
        subtitle: {
            text: 'Source: 信息月统计报表'
        },
        xAxis: {
            categories: [
                '一月',
                '二月',
                '三月',
                '四月',
                '五月',
                '六月',
                '七月',
                '八月',
                '九月',
                '十月',
                '十一月',
                '十二月'
            ]
        },
        yAxis: {
            min: 0,
            title: {
                text: '单位 (条)'
            }
        },
        tooltip: {
            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true
        },
        plotOptions: {
            column: {
                pointPadding: 0.2,
                borderWidth: 0
            }
        },
        series: [{
            name: '公告',
            data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]

        }, {
            name: '资讯',
            data: [83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3]

        }, {
            name: '企业服务',
            data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2]

        }, {
            name: '公文',
            data: [42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1]

        }]
    });
}
